package com.yc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.entity.Categorysecord;
import com.yc.entity.Cmap;
import com.yc.mapper.CmapMapper;
import com.yc.service.ICmapService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * InnoDB free: 4096 kB 服务实现类
 * </p>
 *
 * @author ly
 * @since 2022-05-25
 */
@Service
public class CmapServiceImpl extends ServiceImpl<CmapMapper, Cmap> implements ICmapService {
    @Resource
    private CmapMapper cmapMapper;
    @Override
    public List< Cmap > queryByCtid(int ctid) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("ctid",ctid);
        List<Cmap> list=cmapMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public Integer addCmap(Integer ctid,List< Categorysecord > categorysecordList) {
        Cmap cmap=new Cmap();
        Integer flag=-1;
        cmap.setCtid(ctid);
        for ( int i = 0; i < categorysecordList.size(); i++ ) {
            cmap.setCsid(categorysecordList.get(i).getCsid());
            flag=cmapMapper.insert(cmap);
            if(flag!=1){
                break;
            }
        }
        return flag;
    }
}
